//请修改此变量，与config.inc.asp中的RZ_ROOT的值相同
var RZ_ROOT="/";
function loading(el_name){
	$(el_name).innerHTML="<img src='"+RZ_ROOT+"template/default/images/loading.gif'/>";
}

var sys_lang;
var sys_act;

//根据ID获取元素
function $(id){
	return document.getElementById(id);
}
//根据ID获取值
function v(id){
	return $(id).value;
}
//输出中英文字符串
function outstr(val){
	var tmp;
	if (val.indexOf("|")!=-1)
	{
		tmp=val.split("|");
		if (sys_lang==1)
		{
			return tmp[0];
		}else{
			return tmp[1];
		}
	}else{
		return val;
	}
}
//输出连接错误
function alert_error(){
	if (sys_lang=1)
	{
		alert("Error to connect to the server");
	}else{
		alert("连接服务器出错");
	}
}
function write_error(el_name){
	$(el_name).innerHTML=outstr("Failed to connect to the server|连接服务器出错");
}
function stateerror_common(){
	alert_error();
}
function isNotEmpty(el_name,el_title)
{
	var e=$(el_name);
	e.style.border="1px solid #9093BE";
	if (e.value==""){
		var word=outstr(el_title);
		alert(outstr("Please input the "+word+"|"+"请填写"+word));
		e.style.border="2px solid red";
		e.focus();
		return false;
	}else{
		return true;
	}
}
function isEqual(el1,el1_name,el2,el2_name){
	var e1=$(el1);
	var e2=$(el2);
	if(e1.value!=e2.value){
		e2.style.border="2px solid red";
		var word1=outstr(el1_name);
		var word2=outstr(el2_name);
		alert(outstr(word1+"和"+word2+"必须相等"+"|"+word1+" and "+word2+" must be the same."));
		e2.focus();
		return false;
	}
	return true;
}
function validateEmailByReg(str){
    return(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str));
}
//检查Email地址
function checkEmail(el_name,el_title) {
	e=$(el_name);
	el_value = e.value;
	if (el_value=="")
	{
		return true;
	}
	if(!validateEmailByReg(el_value)) {
		var val;
		val=outstr(el_title);
		alert(outstr(val+" is not valid|"+val+"格式不合法"));
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	return true;
}
//检查电话号码
function checkPhone(el_name,el_title){ 
	e=$(el_name);
	el_value = e.value;
	var reg=/^([\d-+()]*)$/;
	if (reg.test(el_value)==false)
	{
		var word=outstr(el_title);
		alert(outstr(word+"is not valid"+"|"+word+"不合法，请重新填写"));
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	return true;
}

//检查长度
function checkLength(el_name,el_title,min_Len,max_Len){ 
	e=$(el_name);
	el_value = e.value;
	var word=outstr(el_title);
	if (el_value.length>max_Len)
	{
		alert(outstr(word+" is too long ,it should be less then "+max_Len+" characters|"+word+"字符过多，最多"+max_Len+"个字符"));
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	if (el_value.length<min_Len)
	{
		alert(outstr(word+" is too short ,it should be more then "+min_Len+" characters|"+word+"字符过少，最少"+min_Len+"个字符"));
		e.style.border="2px solid red";
		e.focus();
		return false;
	}
	return true;
}
function selectAll(el_name)  {
	var ids=document.getElementsByName(el_name);
	var selectall=$("selectall");
	for(i=0;i<ids.length;i++) {
		ids[i].checked=selectall.checked;   
	}
}

function showproducttype(){
	var producttype = $("index_producttype");
	if(producttype.style.display=="none"){
		producttype.style.display="";
	}else{
		producttype.style.display="none";
	}
}
function hiddeproducttype(){
	var producttype = $("index_producttype");
	producttype.style.display="none";
}
/*首页显示产品_END*/

/*产品留言_BEGIN*/
function ajax_getRecordComments(path,recordid,lang)
{
	sys_lang=lang;
	loading("recordcomment");
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader(RZ_ROOT+"model.asp?modelname=recordcomment&path="+path+"&recordid="+recordid+"&lang="+lang+"&timestamp="+stamp,
		statechange_getRecordComments,stateerror_getRecordComments);
}
function statechange_getRecordComments()
{
var respText = this.req.responseText;
$("recordcomment").innerHTML=respText;
}
function stateerror_getRecordComments(){
	write_error("recordcomment");
}

function ajax_AddRecordComment(path,typeid,recordid,lang,flag)
{
	sys_lang=lang;
	loading("recordcomment_dialog");
	$("recordcomment_dialog").style.display='';
	var date=new Date();
  	var stamp=date.getTime();
	var url=RZ_ROOT+"model.asp?modelname=recordcommentadd&path="+path+"&typeid="+typeid+"&recordid="+recordid+"&lang="+lang+"&flag="+flag+"&timestamp="+stamp;
	var loader = new net.ContentLoader(url,
		statechange_AddRecordComment,stateerror_AddRecordComment);
}
function statechange_AddRecordComment()
{
	var respText = this.req.responseText;
	$("recordcomment_dialog").innerHTML=respText;
}
function stateerror_AddRecordComment(){
	alert_error();
	$("recordcomment_dialog").style.display="none";
}

function checkform_AddRecordComment()
{
	var flag=isNotEmpty("title","Title|标题")&&isNotEmpty("author","Nickname|昵称")&&checkEmail("email","Email")&&isNotEmpty("content","Content|内容")&&checkLength("title","Title|标题",2,50)&&checkLength("author","Nickname|昵称",2,20)&&checkLength("content","Content|内容",5,1000);
	return flag;
}

/*保存商品留言_BEGIN*/
function ajax_saveRecordComment(flag)
{
	if(checkform_AddRecordComment()){
		var date=new Date();
		var stamp=date.getTime();
		var params="title="+v("title");
		params+="&author="+v("author");
		params+="&recordid="+v("recordid");
		params+="&email="+v("email");
		params+="&content="+v("content");
		params+="&path="+v("path");
		params+="&typeid="+v("typeid");
		$("recordcomment_dialog").style.display='';
		var url=RZ_ROOT+"asp/recordcomment_save.asp?lang="+v("lang")+"&timestamp="+stamp;
		if (flag==1)
		{
			var loader = new net.ContentLoader(url,
			statechange_saveRecordComment,stateerror_saveRecordComment,"POST",params);
		}else{
			var loader = new net.ContentLoader(url,
			statechange_saveRecordComment2,stateerror_saveRecordComment,"POST",params);
		}
		
	}
}
function statechange_saveRecordComment()
{
	eval(this.req.responseText);
	$("recordcomment_dialog").style.display="none";
	load_recordcomment();
}
function statechange_saveRecordComment2()
{
	eval(this.req.responseText);
	$("recordcomment_dialog").style.display="none";
	location.reload();
}
function stateerror_saveRecordComment(){
	alert_error();
	$("recordcomment_dialog").style.display="none";
}
/*保存商品留言_END*/

/*产品留言_END*/


//检查添加留言对话框
function checkform_AddComment()
{
	
	var flag=isNotEmpty("title","Title|标题")&&isNotEmpty("author","Nickname|昵称")&&isNotEmpty("email","Email")&&isNotEmpty("content","Content|内容")&&checkEmail("email","Email")&&checkLength("title","Title|标题",2,100)&&checkLength("author","Nickname|昵称",2,40)&&checkLength("content","Content|内容",10,1000);
	if (v("tel")!=""){
		flag=flag&&checkPhone("tel","Phone/Mobile|电话/手机");
	}
	if (v("fax")!=""){
		flag=flag&&checkPhone("fax","Fax|传真");
	}
	return flag;
}


/*保存留言_BEGIN*/
function ajax_saveComment()
{
	sys_lang=v("lang");
	if(checkform_AddComment()){
		
		var date=new Date();
		var stamp=date.getTime();
		var params="";
		var messageform=$("messageform");
		for (var i=0; i<messageform.elements.length; i++)
		{
			params+="&"+messageform.elements[i].name+"="+messageform.elements[i].value;
		}
		if (params!="")
		{
			params=params.substr(1);
		}
		params=params.replace(/\*/g,'');
		var loader = new net.ContentLoader(RZ_ROOT+"asp/guestbook_save.asp?lang="+v("lang")+"&timestamp="+stamp,statechange_saveComment,stateerror_common,"POST",params);
	}
}
function statechange_saveComment()
{
	eval(this.req.responseText);
	location.reload();
}

/*保存留言_END*/
/*专题查看*/
function ajax_showspecial(specialid,lang)
{
	loading("special_content");
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader(RZ_ROOT+"ajax.asp?ajax=2&specialid="+specialid+"&lang="+lang+"&timestamp="+stamp,
		statechange_showspecial,stateerror_showspecial);
}
function statechange_showspecial()
{
var respText = this.req.responseText;
$("special_content").innerHTML=respText;
}
function stateerror_showspecial(){
	write_error("special_content");
}
//关闭留言框
function closeDialog(dialogname){
	var el=$(dialogname);
	el.innerHTML="";
	el.style.display="none";
}
function checkSearchForm(){
	var loc;
	if(isNotEmpty("search_keyword2","Keyword|关键字")&&checkLength("search_keyword2","Keyword|关键字",2,20)){
		if (v("search_level2")!="")
		{
			loc=v("search_level2")+"--"+escape(v("search_keyword2"));
		}else{
			loc=v("search_level1")+"--"+escape(v("search_keyword2"));
		}
		
		document.location=loc;
	}
}

function searchProduct(){
	var loc;
	if(isNotEmpty("search_keyword","Keyword|关键字")&&checkLength("search_keyword","Keyword|关键字",2,20)){
		var url=v("search_category")+"--"+escape(v("search_keyword"));
		document.location=url;
	}
}

function hideElement(id){
	$(id).style.display="none";
}
function displayList(id){
	var el=$(id)
	el.style.display="";
}

/*增加点击数*/
function ajax_AddHits(proc,id)
{
	
	var date=new Date();
  	var stamp=date.getTime();
	var url=RZ_ROOT+"asp/addhits.asp?proc="+proc+"&id="+id+"&timestamp="+stamp;
	var loader = new net.ContentLoader(url,
		statechange_AddHits,stateerror_AddHits);
}
function statechange_AddHits()
{
	var respText = this.req.responseText;
	//alert(respText);
	if (respText.length>0)
	{
		$("hits").innerHTML=respText;
	}
}
function stateerror_AddHits(){
	
}
/*验证表单*/
function checkerror(el,key){
	var itemname=$("itemname_"+el.id).innerHTML;
	var itemtips=$("itemtips_"+el.id);
	switch (key)
	{
	case 0:
		itemtips.innerHTML="";
		if (el.value=="")
		{
			itemtips.innerHTML="<br/><span style='color:red;'>"+itemname+outstr("shoule not be empty|不能为空")+"</span>";
		}
		break;
	}
}

function showsubcategories(sp){
	var par=$("productcategories");
	var chnodes=par.childNodes;
	for (var i=0; i<chnodes.length; i++)
	{
		var span=chnodes[i].childNodes[0];
		var div=chnodes[i].childNodes[2];
		if (span==sp)
		{
			if (div!=null && div!="undefined")
			{
				if (div.childNodes[0]!=null && div.childNodes[0]!="undefined")
				{
					if (div.style.display=="none")
					{
						div.style.display="";
						span.className="icon minus";
					}else{
						div.style.display="none";
						span.className="icon plus";
					}
				}
			}

		}else{
			if (div!=null && div!="undefined")
			{
				if (div.childNodes[0]!=null && div.childNodes[0]!="undefined")
				{
					if (div!=null && div!="undefined")
					{
						div.style.display="none";
						span.className="icon plus";
					}
				}
			}
		}
	}
}

function load_showcategory(){
	var par=$("productcategories");
	var chnodes=par.childNodes;
	var loc=location.toString();
	var select_li;
	var select_span;
	var select_a;
	var p_type=loc.match(/[\/\-]t\d+[-,]\d*/)+"";
	var s;
	s=p_type.substring(1,p_type.length);
	for (var i=0; i<chnodes.length; i++)
	{
		var a=chnodes[i].childNodes[1];
		if (a!=null && a!="undefined"){
			var a_href=a.href;
			if (a_href!=null && a_href!="undefined")
			{
				
				if (a_href.indexOf(s)!=-1)
				{
					select_li=chnodes[i];
					select_a=a;
					break;
				}
			}
		}
	}
	
	for (var i=0; i<chnodes.length; i++)
	{
		var span=chnodes[i].childNodes[0];
		var div=chnodes[i].childNodes[2];
		if (chnodes[i]==select_li)
		{
			if (div!=null && div!="undefined")
			{
				if (div.childNodes[0]!=null && div.childNodes[0]!="undefined")
				{
					if (div.style.display=="none")
					{
						div.style.display="";
						span.className="icon minus";
					}else{
						div.style.display="none";
						span.className="icon plus";
					}
				}
			}
		}else{
			if (div!=null && div!="undefined")
			{
				if (div.childNodes[0]!=null && div.childNodes[0]!="undefined")
				{
					div.style.display="none";
					span.className="icon plus";
				}
			}
		}
	}
}


/*此函数不能删除，用于发送邮件*/
function sendMail(title,content,rand)
{
	var date=new Date();
	var stamp=date.getTime();
	var params="title="+escape(title);
	params+="&content="+escape(content);
	params+="&rand="+rand;
	var loader = new net.ContentLoader(RZ_ROOT+"asp/sendmail.asp?timestamp="+stamp,statechange_sendMail,stateerror_common,"POST",params);
}
function statechange_sendMail()
{
}
function hidepic(pic){
	pic.style.display="none";
}

function ajax_getLeftRecordComments(path,lang)
{
	loading("leftrecordcomment");
	var date=new Date();
  	var stamp=date.getTime();
	var loader = new net.ContentLoader(RZ_ROOT+"model.asp?modelname=leftrecordcomment&path="+path+"&lang="+lang+"&timestamp="+stamp,
		statechange_getLeftRecordComments,stateerror_getLeftRecordComments);
}
function statechange_getLeftRecordComments()
{
var respText = this.req.responseText;
document.getElementById("leftrecordcomment").innerHTML=respText;
}
function stateerror_getLeftRecordComments(){
	document.getElementById("leftrecordcomment").innerHTML="连接服务器出错";
}
/*设置简繁*/
function changeLangu(flag){
	stTransform(flag);
}
function loadlanguage() {
 if(Cookie.Get("l") == "t")
    setTimeout(function(){stTransform(true);},100);
}
function setOnloadEvent(func){
 var oldonload = window.onload;
 if(typeof window.onload != "function"){
  window.onload = func;
 }
 else{
    window.onload = function(){
     oldonload();
     func();
    }
 }
}
setOnloadEvent(loadlanguage);  

var br =navigator.userAgent.toLowerCase();
var ie = /msie/.test(br)&&!/opera/.test(br);
